<?php
/**
 * 登录
 */
namespace app\msgapi\controller;

use app\msgapi\model\System;
use app\Request;
use think\App;
use app\BaseController;
use app\msgapi\service\HsloginService;

class Hslogin extends BaseController
{
    private HsloginService $service;
    public function __construct(App $app, HsloginService $service)
    {
        parent::__construct($app);
        $this->service = $service;
    }

    /**账号密码登录
     * @param Request $request
     * @return \think\response\Json
     */
    public function login(Request $request)
    {
        $data = $request->only(['username','password'],'post');
        return $this->service->login($data['username'], $data['password']);
    }

    /**扫码\单点登录
     * @param Request $request
     * @return \think\response\Json
     * @throws \Throwable
     * @throws \app\utils\UtilsException
     */
    public function wxlogin(Request $request)
    {
        $data = $request->only(['code','state'],'post');
        return $this->service->wxlogin($data);
    }

    /**获取登录前配置
     * @return \think\response\Json
     */
    public function getConfigBeforeLogin()
    {
        return success_json('成功',['login_config'=>System::getSys('login_config'),'set_config'=>System::getSys('set_config')]);
    }
}